<?php

class WebPath extends AtomWidget
{
	private function getActionUrls($url) {
		$url = ltrim($url, '/');
		$controller = Yii::app()->controller;
		$actionNames = $controller->getActionNames();
		$parts = explode('/', $url);
		$actions = array();
		foreach($parts as $part) {
			if ($part == $controller->id || $part == 'index') {
				if (isset($actionNames['index']))
					$actions[] = array('text' => $actionNames['index'], 'url' => "/{$controller->id}");
				else
					$actions[] = array('text' => $part, 'url' => "/{$controller->id}");
			}
			else {
				if (!isset($actionNames[$part]) || !method_exists($controller, 'action'.ucfirst($part)))
					break;
			
				$actions[] = array('text' => $actionNames[$part], 'url' => "/{$controller->id}/$part");
			}
		}
		return $actions;
	}
	protected function prepareContent() {
		$url = Yii::app()->request->url;

//		echo '<pre>';
//		echo $url."\n";
//		echo $controller->id."\n";
//		print_r($actionNames);
//		echo $parts."\n";
//		echo '</pre>';
		$actions = $this->getActionUrls($url);
		return array('actions' => $actions);

	}

}
?>
